package com.example.mymvvmdemo.net.presenter;


import com.example.mymvvmdemo.MyApplication;
import com.example.mymvvmdemo.net.model.IModel;
import com.example.mymvvmdemo.net.model.PostModel;
import com.example.mymvvmdemo.net.view.IView;
import com.example.mymvvmdemo.utils.LogUtils;

import java.util.HashMap;

/**
 * 普通Post请求统一presenter
 */
public class PostPresenter implements IModel.PostModel {

    private PostModel postModel = new PostModel(this);

    private IView.PostView postView;

    public PostPresenter(IView.PostView postView) {
        this.postView = postView;
    }

    public void startLoadPost(String url, HashMap<String, String> hashMap, String type) {
        postModel.startLoadPost(url, MyApplication.getAuthToken(), hashMap, type);
    }


    //回调给view
    @Override
    public void loadPostSuccess(String result, String type, int code) {
        LogUtils.d("load post success type:" + type + ",result:" + result);
        LogUtils.printJson(result, type);
        postView.loadPostSuccess(result, type, code);
    }

    @Override
    public void loadPostFail(String message, String type) {
        LogUtils.d("load post success type:" + type + ",message:" + message);
        postView.loadPostFail(message, type);
    }

    @Override
    public void loadPostAccountError(int code) {
        LogUtils.d("load post account error code :" + code);
        postView.loadPostAccountError(code);
    }

    @Override
    public void loadPostNetWorkError(String message) {
        LogUtils.d("load post network error :" + message);
        postView.loadPostNetWorkError();
    }

}
